package annotationtablemodel;

import annotationtablemodel.suppx.ems.annotatedtable.AnnotatedTableModel;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JDialog;
import javax.swing.JTable;

/**
 * @author Dmitry Savchenko
 */
public class MainDialog extends JDialog {

    public MainDialog() {
        init();
    }

    private void init() {
        AnnotatedTableModel model = null;
        try {
            model = new AnnotatedTableModel(User.class);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        model.setData(getUsers());
        model.fireTableDataChanged();

        JTable table = new JTable(model);
        add(table.getTableHeader(), BorderLayout.NORTH);
        add(table);
        pack();
        setLocationRelativeTo(null);
    }

    private List<User> getUsers() {
        List<User> users = new ArrayList<User>();
        User user = new User();
        user.setName("Роберт");
        user.setHeight(185);
        users.add(user);
        user = new User();
        user.setName("Джон");
        user.setHeight(180);
        users.add(user);
        return users;
    }
}
